package ink.metoo.auto.fishpi.chatroom.handler

import ink.metoo.auto.fishpi.chatroom.Message

object TypeHandlerFactory : TypeHandler {

    private val typeHandlers = mutableListOf<TypeHandler>()

    private fun registerTypeHandler(typeHandler: TypeHandler) {
        typeHandlers.add(typeHandler)
    }

    init {
        registerTypeHandler(MessageTypeHandler())
        registerTypeHandler(RedPacketStatusTypeHandler())
        registerTypeHandler(OnlineTypeHandler())
        registerTypeHandler(DiscussChangedTypeHandler())
        registerTypeHandler(RevokeTypeHandler())
        registerTypeHandler(BarrageTypeHandler())
    }

    override fun handle(text: String, message: Message) {
        typeHandlers.forEach {
            if (it.type.value == message.type) {
                it.handle(text, message)
            }
        }
    }

    override val type: Message.Type
        get() = Message.Type.ALL


}